<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>安平一码通</title>
    <script src="./jquery/jquery.min.js"></script>
</head>

<body>
    <script>
        ////alert(decodeURI(location.search));
        var args = new Object();
        var query = decodeURI(location.search.substring(1)); //获取查询串   
        var pairs = query.split("&"); //在逗号处断开  
        ////alert(pairs);
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('='); //查找name=value   
            if (pos == -1) continue; //如果没有找到就跳过   
            ////alert(pos);
            var argname = pairs[i].substring(0, pos); //提取name   
            var value = pairs[i].substring(pos + 1); //提取value   
            args[argname] = unescape(value); //存为属性   
        }
        var rukouName = args.state;
        var code = args.code;
        ////alert('middle登记地址:' + rukouName);
        ////alert('middle页面code:' + code);
        // 利用code判断是不是注册过(根据新修改需求还需要判断去的是哪一种类型,在本地存储存储什么值,然后跳转到哪种表单)
        if (code) {
            $.ajax({
                url: "http://351hj04970.qicp.vip/ymtUser/query",
                type: "get",
                data: {
                    wxcode: code
                },
                success: function (res) {
                    var urls=""
                    ////alert("success")
                    if (res.code == 0) {
                        ////alert("注册了!!!")
                        // 注册过
                        // 2.拿状态(如果是第二次登录,那么身份证号和姓名变成只读状态)
                        // 存本地存储
                        localStorage.setItem("name",res.data.name)
                        localStorage.setItem("idCard",res.data.idCard)
                        localStorage.setItem("phone",res.data.phone)
                        ////alert("name:"+localStorage.getItem('name'))
                        ////alert("idCard:"+localStorage.getItem('idCard'))
                        ////alert("phone:"+localStorage.getItem('phone'))
                        // localStorage.setItem("code",0000)
                        urls="http://hesuan.city1000.cn/register/communitycopy.html"
                    } else {
                        // 未注册
                        ////alert("未注册!!!!")
                        urls="http://hesuan.city1000.cn/register/community.html"
                    }
                    //跳转到用户登记页面
                    $.ajax({
                        type: "get",
                        url: "http://user.city1000.top/wechat/wxScan", //自己填写请求地址
                        data: {
                            url: window.location.href
                        },
                        success: function (result) {
                            ////alert("middle页面的appid:"+result.appId)
                            var appID = result.appId
                            var redirectUri = encodeURI(
                                urls
                            ); // 授权成功后重定向地址(目前是首页)
                            var state = rukouName; // 状态标识（用于项目拓展)
                            // 跳转授权(拿到用户信息)
                            var strUrl =
                                "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
                                appID +
                                "&redirect_uri=" + redirectUri +
                                "&response_type=code&scope=snsapi_base&state=" + state +
                                "#wechat_redirect";
                            window.location.href = strUrl;
                        }
                    })
                },
                error: function (err) {
                    //alert("请您重新进入当前页面:" + err.status)
                    window.location.go(-2)
                }
            })
        } else {
            //alert("请重新扫码!!!")
        }
    </script>
</body>

</html>